<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>HelloWorld</title>
    <script type="text/javascript" src="../assets/js/vue.js"></script>
</head>
<body>
    <h1>Hello World!</h1>
    <hr>
    <div id="app">
        {{message}}
        <component v-bind:is="who"></component>
        <button @click="changeComponent">change Component</button>
    </div>

    
    <script type="text/javascript">
       var componentA={
           template : `<div style="color:red">I am componentA.</div>`
       }
       var componentB={
           template : `<div style="color:blue">I am componentB.</div>`
       }
       var componentC={
           template : `<div style="color:pink">I am componentC.</div>`
       }


        var app = new Vue({
            el:'#app',
            data:{
                //根据动态值来显示不同的component(组件)
                who:'componentC'
            },
            components:{
                "componentA" : componentA,
                "componentB" : componentB,
                "componentC" : componentC
                
            },
            methods:{
                changeComponent:function(){
                    if (this.who == "componentA"){
                        this.who = "componentB";
                    } else if (this.who == "componentB"){
                        this.who = "componentC"
                    } else{
                        this.who = "componentA";
                    }
                }
            }
        })
    </script>
</body>
</html>